﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using NetBay.Core.Log;

namespace Rio.Flow.Business
{
    public class ConvertField
    {
        /// <summary>
        /// Convert an object to its equivalent DateTime. If null then DateTime.DateMin
        /// </summary>
        /// <param name="p_oSource">string to convert</param>
        /// <returns>DateTime equivalent</returns>
        public static DateTime ToDateTime(string p_oSource)
        {
            DateTime l_oDt;
            return DateTime.TryParse(p_oSource, out l_oDt) ? l_oDt : default(DateTime);
        }

        /// <summary>
        /// Convert to TimeSpan
        /// </summary>
        /// <param name="dateTime">The date time.</param>
        /// <returns></returns>
        public static TimeSpan ToTimeSpan(DateTime dateTime)
        {
            return TimeSpan.Parse(dateTime.ToString("T"));
        }
    }
}
